define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	
	var Model = function(){
		this.callParent();
		this.fPhone = "";
		this.fPassword = "";
		this.fID = "";
	};
	
	//图片路径转换
	Model.prototype.toUrl = function(url){
		return url ? require.toUrl(url) : "";
	};
	
	
	Model.prototype.loginBtnClick = function(event){
		//var passCheck = this.comp("passCheck").val();
		var phoneInput = this.comp("phoneInput").val();
		var passwordInput = this.comp("passwordInput").val();
		var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
		if(!(reg.test(phoneInput))){
			alert("手机号码格式不正确，请重新输入");
		}else{
			var UserData = this.comp("UserData");
			var memberData = this.comp("memberData");
			UserData.clear();
			UserData.setFilter("fPhoneFilter","fPhone ='"+ phoneInput +"'");
			UserData.refreshData();
			if (UserData.count() > 0){
				memberData.clear();
				memberData.setFilter("fPhoneFilter","fPhone ='"+ phoneInput +"'");
				memberData.setFilter("fPasswordFilter","fPassword ='"+ passwordInput +"'");
				memberData.refreshData();
				if(memberData.count() > 0){
					justep.Shell.closePage();
					justep.Util.hint("恭喜您，手机号为"+ phoneInput +"的用户，登录成功！");
					justep.Shell.showPage("main", {
						keyValue : phoneInput
					});
					localStorage.setItem('LoginState', phoneInput);
					memberData.setValue("fLoginState", "登录");
					memberData.saveData();
					location.reload();
				}
				else
					justep.Util.hint("对不起，密码错误！登录失败！");
			}
			else
				justep.Util.hint("对不起，手机号码不存在，请进行注册！");
		}
	};
	
	
	Model.prototype.registerBtnClick = function(event){
		justep.Shell.showPage("register");
	};
	
	
	
	Model.prototype.backBtnClick = function(event){
		justep.Shell.fireEvent("onHomeContent",{});
		justep.Shell.showMainPage(); 
	};
	Model.prototype.modelLoad = function(event){
		if(localStorage.getItem('LoginState') != " " && localStorage.getItem('LoginState') != undefined){
			justep.Shell.showPage("main");
			justep.Shell.closePage();
		}
	};
	
	
	
	
	
	
	return Model;
});
